﻿namespace DeltaGroup.WheelOfJeopardy.ChallengeManager
{
    using System.Collections.ObjectModel;

    public class PhraseMatchResult
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="PhraseMatchResult"/> class.
        /// </summary>
        public PhraseMatchResult()
        {
            Matches = new ObservableCollection<string>();
            Misses = new ObservableCollection<string>();
            Matches.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Matches_CollectionChanged);
            Misses.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Misses_CollectionChanged);
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        /// Gets or sets the matched tokens.
        /// </summary>
        /// <value>The matched tokens.</value>
        public int MatchedTokens
        {
            get; internal set;
        }

        /// <summary>
        /// Gets or sets the matches.
        /// </summary>
        /// <value>The matches.</value>
        public ObservableCollection<string> Matches
        {
            get; private set;
        }

        /// <summary>
        /// Gets or sets the misses.
        /// </summary>
        /// <value>The misses.</value>
        public ObservableCollection<string> Misses
        {
            get; private set;
        }

        /// <summary>
        /// Gets or sets the unmatched tokens.
        /// </summary>
        /// <value>The unmatched tokens.</value>
        public int UnmatchedTokens
        {
            get; internal set;
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Handles the CollectionChanged event of the Matches control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
        void Matches_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            MatchedTokens = Matches.Count;
        }

        /// <summary>
        /// Handles the CollectionChanged event of the Misses control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
        void Misses_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            UnmatchedTokens = Misses.Count;
        }

        #endregion Methods
    }
}